<?php

namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;

class Users extends Authenticatable
{
    // 表名称
    protected $table = 'users';
    // 开启自动时间戳
    public $timestamps = true;
    // 日期都存储为时间戳
    protected $dateFormat = 'U';

    public function cafe()
    {
        return $this->belongsToMany('App\Cafe', 'cafe_mapping_user', 'user_id', 'cafe_id');
    }

    public function city()
    {
        return $this->belongsToMany('App\City', 'user_mapping_city', 'user_id', 'city_id');
    }

    public function beanBaker()
    {
        return $this->hasOne('App\Barista', 'user_id', 'id');
    }

    public function role()
    {
        return $this->belongsToMany('App\Role', 'user_mapping_role', 'user_id', 'role_id');
    }

    public function likeCafe()
    {
        return $this->belongsToMany('App\Cafe', 'user_likeCafes', 'user_id', 'cafe_id');
    }

    public function visitedCafes()
    {
        return $this->belongsToMany('App\Cafe', 'user_visited_cafe', 'user_id', 'cafe_id');
    }

    public function user_citys()
    {
        return $this->belongsToMany('App\City', 'user_citys', 'user_id', 'city_id');
    }

    public function partner()
    {
        return $this->belongsToMany('App\Partner', 'user_mapping_partner', 'user_id', 'partner_id');
    }

    public function belongPartner()
    {
        return $this->hasOne('App\Partner', 'partner_id', 'id');
    }

    public function assets()
    {
        return $this->hasMany('App\Assets', 'user_id', 'id');
    }

    public function adminMenu()
    {
        return $this->belongsToMany('App\AdminMenu', 'user_mapping_admin_menu', 'user_id', 'admin_menu_id');
    }
}
